﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI_Test
{
    public partial class SubFormMYSQLConnection : Form
    {
        public SubFormMYSQLConnection()
        {
            InitializeComponent();
            //textBoxMYSQLServerName.Text = "localhost";
            //textBoxMYSQLDBName.Text = "wcdb";
            //textBoxMYSQLUserId.Text = "root";
            //textBoxMYSQLPassword.Text = "";
        }

        private void SubFormMYSQLConnection_Load(object sender, EventArgs e)
        {
            this.MaximizeBox = false;
            this.MinimizeBox = false;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!validateUserInput())
            {
                return;
            }
        }
        private bool validateUserInput()
        {
            if (textBoxMYSQLServerName.Text.Trim() == string.Empty || textBoxMYSQLDBName.Text.Trim() == string.Empty
                || textBoxMYSQLUserId.Text.Trim() == string.Empty)
            {
                
                MessageBox.Show("Please fill all required fields.", "Error: Invalid Entry");
                return false;
            }

            return true;
        }
        //private bool validateUserInput()
        //{
        //    bool isValid = true;
        //    if (textBoxMYSQLServerName.Text.Trim() == string.Empty)
        //    {
        //        MessageBox.Show("Server name is required.", "Error: Invalid entry");
        //        isValid = false;
        //    }
        //    if (textBoxMYSQLDBName.Text.Trim() == string.Empty)
        //    {
        //        MessageBox.Show("Database name is required.", "Error: Invalid entry");
        //        isValid = false;
        //    }
        //    if (textBoxMYSQLUserId.Text.Trim() == string.Empty)
        //    {
        //        MessageBox.Show("User ID is required.", "Error: Invalid entry");
        //        isValid = false;
        //    }
        //    //if (textBoxMYSQLPassword.Text.Trim() == string.Empty)
        //    //{
        //    //    MessageBox.Show("Password is required.", "Error: Invalid entry");
        //    //    isValid = false;
        //    //}
        //    return isValid;
        //}

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnTestConnection_Click(object sender, EventArgs e)
        {
            try
            {
                SHARED.MYSQL o = new SHARED.MYSQL(textBoxMYSQLServerName.Text, textBoxMYSQLDBName.Text, textBoxMYSQLUserId.Text, textBoxMYSQLPassword.Text);

                if (o.isConnected())
                {
                    MessageBox.Show("Successful", "Status");
                    return;
                }
                MessageBox.Show("Failed", "Status");
            }
            catch
            {
                throw;
            }
        }

        private void labelUserId_Click(object sender, EventArgs e)
        {

        }
    }
}
